package com.soft.sitegenerator.business.hibernate;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import com.soft.sitegenerator.dao.HibernateDAO;
import com.soft.sitegenerator.exceptions.ObjectNotFoundException;

public class SitePage {

	private Long id;

	private String name;

	private String title;

	private String contextPath;

	private Sheet sheet;

	private WebSite webSite;

	private Set templates = new HashSet();

	public Set getTemplates() {
		return templates;
	}

	public void setTemplates(Set templates) {
		this.templates = templates;
	}

	public String getContextPath() {
		return contextPath;
	}

	public void setContextPath(String contextPath) {
		this.contextPath = contextPath;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Sheet getSheet() {
		return sheet;
	}

	public void setSheet(Sheet sheet) {
		this.sheet = sheet;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public WebSite getWebSite() {
		return webSite;
	}

	public void setWebSite(WebSite webSite) {
		this.webSite = webSite;
	}

	private HibernateDAO hibernateDAOHib;

	// HIBERNATE DAO
	public HibernateDAO getHibernateDAOHib() {
		return hibernateDAOHib;
	}

	public void setHibernateDAOHib(HibernateDAO hibernateDAOHib) {
		this.hibernateDAOHib = hibernateDAOHib;
	}

	public void load() throws ObjectNotFoundException {
		hibernateDAOHib.load(this, this.getId());
	}

	public void save() {
		hibernateDAOHib.save(this);
	}

	public void update() {
		hibernateDAOHib.update(this);
	}

	public void delete() {
		hibernateDAOHib.delete(this);
	}

	public boolean exist() {
		try {
			hibernateDAOHib.exist(this, this.getId());
			return true;
		} catch (ObjectNotFoundException e) {
			return false;
		}
	}

	public Collection findAll() {
		return hibernateDAOHib.find("from SitePage order by name");
	}

}
